package com.fyzk.activity.user.tobuydetail;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.fyzk.base.BaseActivity;
import com.fyzk.activity.lottery.togetherbuy.HeMaiGenDanActivity;
import com.fyzk.activity.user.xiangxi.ContinueBuy;
import com.fyzk.constants.ConstantsDJ;
import com.fyzk.dialog.DJ_ProgressDialog;
import com.fyzk.interfaces.onTopTitleClickListener;
import com.tyjc.lottery.R;
import com.fyzk.utils.HandlerTypeUtils;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.view.TopTitleView;
/**
 *	合买详情页 
 */
public class ToBuyDetailBaseActivity extends BaseActivity implements
		onTopTitleClickListener {

	private TopTitleView topView;

	private ImageView lottery_iv;
	private TextView lottery_tv;
	private TextView wcode_tv;
	private TextView renGou_tv;
	private TextView prizeMoney_tv;
	private TextView state_tv;
	private TextView userFaQi_tv;
	private TextView money_tv;
	private TextView tiCheng_tv;
	private TextView betInfor_tv;
	
	private RelativeLayout mingXi_rl;
	private TextView baoMi_tv;
	private LinearLayout race_ll;
	private boolean isShowMingXi = true;
	
	private TextView title_tv;
	private TextView content_tv;
	private TextView time_tv;
	private TextView id_tv;

	private TextView jiXu_tv;
	private TextView genDan_tv;
	
	//数据
	private String id;
	private String lotteryType = "";
	
	private int isFollow = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dj_usercenter_hemai_detail);

		id = getIntent().getStringExtra(IntentParamUtils.BETDETAILID);
		isFollow = getIntent().getIntExtra(IntentParamUtils.ISFOLLOW,0);
		initView();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		DJ_ProgressDialog.show(getContext(), true, true);
	};

	@Override
	protected void parserMessage(Message msg) {
		DJ_ProgressDialog.dissmiss();
		super.parserMessage(msg);
		switch (msg.what) {
		case HandlerTypeUtils.ZY_HANDLER_TYPE_LOAD_HEMAIRECORDDETAIL_SUCCESS:
			fuZhi();
			break;
		case HandlerTypeUtils.ZY_HANDLER_TYPE_LOAD_DATA_FAIL:
			Toast.makeText(this, "数据加载失败", Toast.LENGTH_SHORT).show();
			break;
		default:
			break;
		}
	}

	private void initView() {
		// 顶部
		topView = (TopTitleView) findViewById(R.id.hm_betdetail_topTitle);
		topView.setCenterText(R.string.hm_xiangqing);
		topView.setRightVisible(View.VISIBLE);
		topView.setRightImg(R.drawable.hm_refresh_click);
		topView.setOnTitleClickListener(this);

		// 中间
		lottery_iv = (ImageView) findViewById(R.id.hm_betdetail_lottery_iv);
		lottery_tv = (TextView) findViewById(R.id.hm_betdetail_lottery_tv);
		wcode_tv = (TextView) findViewById(R.id.hm_betdetail_wcode);
		renGou_tv = (TextView) findViewById(R.id.hm_betdetail_rengou_tv);
		prizeMoney_tv = (TextView) findViewById(R.id.hm_betdetail_prizemoney_tv);
		state_tv = (TextView) findViewById(R.id.hm_betdetail_state_tv);
		userFaQi_tv = (TextView) findViewById(R.id.hm_betdetail_user_faqi);
		money_tv = (TextView) findViewById(R.id.hm_betdetail_money_tv);
		tiCheng_tv = (TextView) findViewById(R.id.hm_betdetail_ticheng);
		betInfor_tv = (TextView) findViewById(R.id.hm_betdetail_betinfor);
		
		mingXi_rl = (RelativeLayout) findViewById(R.id.hm_betdetail_xiangxi_rl);
		mingXi_rl.setOnClickListener(this);
		baoMi_tv = (TextView) findViewById(R.id.hm_betdetail_baomi_tv);
		race_ll = (LinearLayout) findViewById(R.id.hm_betdetail_race_ll);
		
		title_tv = (TextView) findViewById(R.id.hm_betdetail_title);
		content_tv = (TextView) findViewById(R.id.hm_betdetail_content);
		time_tv = (TextView) findViewById(R.id.hm_betdetail_time);
		id_tv = (TextView) findViewById(R.id.hm_betdetail_id);
		
		//底部
		jiXu_tv = (TextView) findViewById(R.id.hm_betdetail_jixu_tv);
		jiXu_tv.setOnClickListener(this);
		genDan_tv = (TextView) findViewById(R.id.hm_betdetail_gendan_tv);
		genDan_tv.setOnClickListener(this);
	}
	//赋值
	private void fuZhi() {
	}

	private void setPrize_and_state(String prizeMoney, String stateId){
		prizeMoney_tv.setText(prizeMoney);
		state_tv.setText(ConstantsDJ.heMai_state(stateId));
		if (stateId.equals("已中奖")) {
			prizeMoney_tv.setTextColor(Color.RED);
		}else if (stateId.equals("认购中")) {//认购中
			genDan_tv.setVisibility(View.VISIBLE);
			prizeMoney_tv.setText("-");
		}else{
			prizeMoney_tv.setText("-");
		}
	}
	

	@Override
	public void onLeftClick() {
		// TODO Auto-generated method stub
		onBackPressed();
	}

	@Override
	public void onCenterClick() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onRightClick() {
		// TODO Auto-generated method stub
		DJ_ProgressDialog.show(getContext(), true, true);
//		requestData(SchemaDef.HEMAI_BETDETAIL);
	}
	@Override
	public void onRight2Click() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.hm_betdetail_xiangxi_rl://对阵详细 
			isShowMingXi = !isShowMingXi;
			if (isShowMingXi) {
				race_ll.setVisibility(View.VISIBLE);
			}else{
				race_ll.setVisibility(View.GONE);
			}
			break;
		case R.id.hm_betdetail_jixu_tv://继续购彩
			if (ContinueBuy.jiXu(getContext(), lotteryType)) {
				finish();
			}
			break;
		case R.id.hm_betdetail_gendan_tv://继续跟单
			Intent intent = new Intent(getContext(), HeMaiGenDanActivity.class);
			intent.putExtra(IntentParamUtils.HM_HALLDETAIL_ID, id);
			startActivity(intent);
			finish();
			break;
		default:
			break;
		}
	}
}
